#include "pch.h"
#include "tree_list_test.h"

#include <boostext/container/tree_list.hpp>
using boostext::tree_list;
using std::string;




void tree_list_test::construction()
{
	/**
	* Testcase #1: See if it compiles & basic interface test
	* The following tree is created:
	*
	* "A string"
	* -- "A substring"
	* --."A second substring"
	* -- "A sub tree"
	* ---- "A subsub string"
	* ---- "Another subsub string"
	*/
	tree_list<string> t( "A string" );
	t.push_back( "A substring" );
	t.insert( t.end(), "A second substring" );

	tree_list<string> s( "A sub tree" );
	s.push_back( "A subsub string" );
	s.insert( s.begin(), "Another subsub string" );

	t.push_back( s );

	// Those tests simply "walk" the tree and verfy every single element
	ASSERT_EQUAL( "A string", t.get() );
	ASSERT_EQUAL( 3, t.size() );

	tree_list<string>::iterator i = t.begin();
	ASSERT_EQUAL( "A substring", i->get() );
	ASSERT_EQUAL( 0, i->size() );

	std::advance( i, 1 );
	ASSERT_EQUAL( "A second substring", i->get() );
	ASSERT_EQUAL( 0, i->size() );

	std::advance( i, 1 );
	ASSERT_EQUAL( "A sub tree", i->get() );
	ASSERT_EQUAL( 2, i->size() );

	tree_list<string>::iterator o = i->begin();
	ASSERT_EQUAL( "Another subsub string", o->get() ); // because it gets inserted at the front
	ASSERT_EQUAL( 0, o->size() );

	std::advance( o, 1 );
	ASSERT_EQUAL( "A subsub string", o->get() );
	ASSERT_EQUAL( 0, o->size() );



	tree_list<int> r( 50 );
	r.push_back( 10 );
	r.push_back( 100 );
	r.push_back( 20 );
	r.push_back( 10 );

	ASSERT_EQUAL( 50, r.get() );
	ASSERT_EQUAL( 4, r.size() );
	r.remove( 10 ); // When removing elements that hold a 10, only 2 should be left
	ASSERT_EQUAL( 2, r.size() );
	r.sort(); // When sorting, the 20 should be the first element
	ASSERT_EQUAL( 20, r.front().get() );
	ASSERT_EQUAL( 100, r.back().get() );
}
///////////////////////////////////////////////////////////////////////////////////////////////////




void tree_list_test::operator()()
{
	construction();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
